<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ page import="java.util.Iterator" %>
<%@ page import="model.Brand" %>
<%@ page import="model.Present" %>
<%@ page import="model.Producer" %>
<%@ page import="model.Material" %>
<%@ page import="model.CategoryBean" %>
<!DOCTYPE html >

<% 

Iterator<Present> presents = (Iterator<Present>)request.getAttribute("presents");
Iterator<Brand> brands = (Iterator<Brand>)request.getAttribute("brands"); 
Iterator<Producer> producers = (Iterator<Producer>)request.getAttribute("producers"); 
Iterator<Material> materials = (Iterator<Material>)request.getAttribute("materials"); 
Iterator<CategoryBean> categories = (Iterator<CategoryBean>)request.getAttribute("categories"); 
Present present;
Brand brand;
Producer producer;
Material material;
CategoryBean category;
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Стъпка 1</title>
<link rel="stylesheet" href="/Store/css/Administration.css" type="text/css">
<script src="jquery-2.1.1.min.js"> </script>

<script>

function addElement(className){
    
    var parentHTML = $("."+className).filter(":first").html();
    var child = document.createElement("tr");
    child.innerHTML = parentHTML;
    var removeButton = document.createElement("button");
    text = document.createTextNode("Премахни");
    removeButton.appendChild(text);
    $(removeButton).attr("type","button");
    $(removeButton).click(function(){
       $(this).parent().remove();
    
    });
    child.appendChild(removeButton);
    $(child).attr("class",className);
    $("."+className).filter(":last").after(child);
    
}
</script>
</head>
<body>
<div class="container">
<div class="main">
<form action="DefineBasicProductFeatures1" method="post" autocomplete="off">
	<table class="center">
		<tr> <td> Oписание:</td> <td> <input type="text" name="description" required> </td></tr>
		<tr class="feature">
			<td>Характеристика:</td>
			<td>
				<input type="text" name="features[]">
			</td>
			<td> <button type="button" onclick="addElement('feature')"> Добави </button> </td>
		</tr>
		<tr class="categories">
			<td>Категория:</td>
			<td>
				<select name="categoryIds[]">
					<% while(categories.hasNext()){
						category = categories.next(); %>
						<option value=<%=category.getId()%>> <%=category.getName()%></option>
					<%}%>
				</select>
			</td>
			<td> <button type="button" onclick="addElement('categories')"> Добави </button> </td>
		</tr>
		<tr> <td> Промоционална цена:</td> <td> <input type="number" step="any" min="0.01" name="promotional_price"> </td></tr>
		<tr> <td> Цена:</td> <td> <input type="number" step="any" min="0.01" name="price" required> </td></tr>
		<tr> <td> Цена на едро:</td> <td> <input type="number" step="any" min="0.01" name="wholesale_price"> </td></tr>
		<tr>
			<td>Производител:</td>
			<td>
				<select name="producerId">
					<% while(producers.hasNext()){
						producer = producers.next(); %>
						<option value=<%=producer.getId() %>> <%=producer.getDescription() %></option>
					<%}%>
				</select>
			</td>
		</tr>
		<tr>
			<td>Mарка:</td>
			<td>
				<select name="brandId">
					<option value="0"> няма </option>
					<% while(brands.hasNext()){
						brand = brands.next(); %>
						<option value=<%=brand.getId()%>> <%=brand.getDescription() %></option>
					<%}%>
				</select>
			</td>
		</tr>
		<tr class="material">
			<td>Материал:</td>
			<td>
				<select name="materialIds[]">
					<% while(materials.hasNext()){
						material = materials.next(); %>
						<option value=<%=material.getId()%>> <%=material.getDescription() %></option>
					<%}%>
				</select>
			</td>
			<td> Процент: </td>
			<td> <input type="number"  required max="100" min="0" name="materialPercents[]"> </td>
			<td> <button type="button" onclick="addElement('material')"> Добави </button> </td>
		</tr>
		
		<tr class="present">
			<td>Подарък:</td>
			<td>
				<select name="presentIds[]">
					<option value="0"> няма </option>
					<% while(presents.hasNext()){
						present = presents.next(); %>
						<option value=<%=present.getId()%>> <%=present.getDescription() %></option>
					<%}%>
				</select>
			</td>
			<td> <button type="button" onclick="addElement('present')"> Добави </button> </td>
		</tr>
		<tr>
			<td> <input type="submit" value="Продължи"></td>
			<td class="cancel"> <a href="Supplier.html"> <button type="button"> Отмени </button> </a></td>
		</tr>
	</table>
</form>
</div>
</div>
</body>
</html>